export default {
    split: function(str, separator) {
        if (str === null) {
            return [];
        }
        if (str === '') {
            return [''];
        }
        if (separator === '') {
            return [str];
        }
        return str.split(separator);
    },
    join: function(arr, separator) {
        if (!Array.isArray(arr)) {
            return false;
        }
        return arr.join(separator);
    },
    deleteWhitespace: function(str) {
        return str.replace(/\s+/g, '');
    },
    repeat: function(str, count) {
        return str.repeat(count);
    },
    reverse: function(str) {
        return str.split('').reverse().join('');
    },
    swapCase: function(str) {
        return str.split('').map(char => {
            return char === char.toUpperCase() ? char.toLowerCase() : char.toUpperCase();
        }).join('');
    },
    lowerCase: function(str) {
        return str.toLowerCase();
    },
    upperCase: function(str) {
        return str.toUpperCase();
    },
    capitalize: function(str) {
        return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
    },
    uncapitalize: function(str) {
        return str.charAt(0).toLowerCase() + str.slice(1);
    },
    substring: function(str, start, end = undefined) {
        if (end === undefined) {
            end = str.length;
        }
        return str.substring(start, end);
    },
    right: function(str, len) {
        return str.substring(str.length - len);
    },
    replace: function(str, searchStr, replacement) {
        return str.replace(new RegExp(searchStr, 'g'), replacement);
    },
    replaceOnce: function(str, searchStr, replacement) {
        const index = str.indexOf(searchStr);
        if (index === -1) {
            return str;
        }
        return str.substring(0, index) + replacement + str.substring(index + searchStr.length);
    },
    contains: function(str, searchStr) {
        return str.includes(searchStr);
    },
    containsIgnoreCase: function(str, searchStr) {
        return str.toLowerCase().includes(searchStr.toLowerCase());
    },
    countMatches: function(str, char) {
        return str.split(char).length - 1;
    },
    indexOf: function(str, search) {
        return str.indexOf(search);
    },
    lastIndexOf: function(str, search) {
        return str.lastIndexOf(search);
    },
    startsWith: function(str, prefix) {
        return str.startsWith(prefix);
    },
    endsWith: function(str, suffix) {
        return str.endsWith(suffix);
    },
    isEmpty: function(str) {
        return str === null || str === undefined || str.trim() === '';
    },
    isNotEmpty: function(str) {
        return !this.isEmpty(str);
    },
    length: function(str) {
        return str ? str.length : 0;
    },
    countChineseCharacters: function(str) {
        return [...str].length;
    }
};